package Set.TreeSet;

import java.util.TreeSet;

public class Test4 {
    public static void main(String[] args) {
        TreeSet<Student1> ts = new TreeSet<>();

        Student1 s1 = new Student1("zhangsan", 23, 90, 99, 50);
        Student1 s2 = new Student1("lisi", 24, 90, 98, 50);
        Student1 s3 = new Student1("wangwu", 25, 95, 100, 30);
        Student1 s4 = new Student1("zhaoliu", 26, 60, 99, 70);
        Student1 s5 = new Student1("qianqi", 26, 70, 80, 70);

        ts.add(s1);
        ts.add(s2);
        ts.add(s3);
        ts.add(s4);
        ts.add(s5);

        for (Student1 t : ts) {
            System.out.println(t);
        }
    }
}

class Student1 implements Comparable<Student1> {
    private String name;
    private int age;
    private int chinese;
    private int math;
    private int english;

    public Student1() {
    }

    public Student1(String name, int age, int chinese, int math, int english) {
        this.name = name;
        this.age = age;
        this.chinese = chinese;
        this.math = math;
        this.english = english;
    }

    /**
     * 获取
     *
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     *
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     *
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     *
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    /**
     * 获取
     *
     * @return chinese
     */
    public int getChinese() {
        return chinese;
    }

    /**
     * 设置
     *
     * @param chinese
     */
    public void setChinese(int chinese) {
        this.chinese = chinese;
    }

    /**
     * 获取
     *
     * @return math
     */
    public int getMath() {
        return math;
    }

    /**
     * 设置
     *
     * @param math
     */
    public void setMath(int math) {
        this.math = math;
    }

    /**
     * 获取
     *
     * @return english
     */
    public int getEnglish() {
        return english;
    }

    /**
     * 设置
     *
     * @param english
     */
    public void setEnglish(int english) {
        this.english = english;
    }

    public String toString() {
        return "Student1{name = " + name + ", age = " + age + ", chinese = " + chinese + ", math = " + math + ", english = " + english + "}";
    }


    @Override
    public int compareTo(Student1 o) {
        int sum1 = this.getChinese() + this.getEnglish() + this.getMath();

        int sum2 = o.getChinese() + o.getEnglish() + o.getMath();

        int i = sum1 - sum2;

        i = i == 0 ? this.getChinese() - o.getChinese() : i;
        i = i == 0 ? this.getMath() - o.getMath() : i;
        i = i == 0 ? this.getEnglish() - o.getEnglish() : i;
        i = i == 0 ? this.getAge() - o.getAge() : i;
        i = i == 0 ? this.getName().compareTo(o.getName()) : i;

        return i;
    }
}